<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "" "">
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:w="http://www.apusic.com/jsf/widget" xmlns:layout="http://www.apusic.com/jsf/layout"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:ajax="http://www.apusic.com/jsf/ajax"
	renderKitId="AJAX">
	<w:head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<w:stylesheet src="/css/kmp4.css" type="text/css"></w:stylesheet>
		<script type="text/javascript">
		//<![CDATA[
			function showUpload(){
				var fileUpload=eval("window.parent.#{component_listAttachmentForEditBean.id}_fileUpload_jsvar");
				fileUpload.url='#{facesContext.externalContext.requestContextPath}/uploadAttachment?beanClass=#{component_listAttachmentForEditBean.beanClass}&beanId=#{component_listAttachmentForEditBean.beanId}&attachmentType=#{component_listAttachmentForEditBean.attachmentType}';
				fileUpload.show();
			}
			function downloadAttach(){
				var sid = attachmentComponent.getSelectionModel().getSelected().get('id');
				window.location.href='#{facesContext.externalContext.requestContextPath}/downloadAttachment?id='+sid;
			}
			function deleteAttach(){
				if(attachmentComponent.getSelections().length == 0){
					alert("请选择一条记录！");
					return false;
				}
				return confirm('你确定要删除吗？');
			}
			function formatFloat(src, pos){
    			return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
    		}
			function transLength(v, m , r, rIndex){
				if(1024*1024*10>v)
					return formatFloat(v/1024,2)+'KB';
				return formatFloat(v/1024/1024,2)+'MB';
			}
			function reloadAttach(){
				//alert('aaaa');
				var store=attachmentComponent.getStore();
				store.reload(store.lastOptions);
			}
		//]]>
		</script>
	</w:head>
	<w:page title="附件">
		<layout:panel border="false" autoHeight="true" autoWidth="true" header="false"
			styleClass="k4-view-window">
			<w:form>
				<w:toolBar>
					<w:button value="添加附件" id="addFile" alwaysSubmit="false" onclick="javascript:showUpload();" />
					<w:separator></w:separator>
					<w:button value="删除附件" id="delFile" onclick="return deleteAttach();" />
				</w:toolBar>
			</w:form>
			<w:dataGrid id="attachmentsList" paged="false" showRowNumber="true" jsvar="attachmentComponent"
				border="false" selectionModel="#{selectionModel.checkbox}"
				ondblclick="javascript:downloadAttach();" singleSelect="false" autoExpandColumn="2"
				autoHeight="true">
				<w:outputColumn header="ID" id="id" hidden="true"></w:outputColumn>
				<w:outputColumn header="文件名" id="fileName" wrap="true"></w:outputColumn>
				<w:outputColumn header="大小" id="length" width="100" clientFormatter="transLength"></w:outputColumn>
				<w:outputColumn header="上传时间" id="createTime" width="85" converter="dateFormatter"></w:outputColumn>
				<w:outputColumn header="上传人" id="author" width="70"></w:outputColumn>
			</w:dataGrid>
		</layout:panel>
	</w:page>
</f:view>